package com.itheima.pulltorefreshlib.internal;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;

import com.itheima.pulltorefreshlib.PullToRefreshBase;
import com.itheima.pulltorefreshlib.R;

/**
 * ====================Android App====================<br>
 * 作   者：Hzj<br>
 * 创建时间：2017/12/12 13:53<br>
 * 公   司：浙江有所为网络科技有限公司<br>
 * 修改日志：<br>
 * 作   用：老有她项目下拉加载上拉刷新样式(仿美团样式)<br>
 * ====================Android App====================<br>
 */

@SuppressLint("ViewConstructor")
public class Right2DoStyleLoadingLayout extends LoadingLayout {

    private AnimationDrawable animationDrawable;

    public Right2DoStyleLoadingLayout(Context context, PullToRefreshBase.Mode mode, PullToRefreshBase.Orientation scrollDirection, TypedArray attrs) {
        super(context, mode, scrollDirection, attrs);
    }

    @Override
    protected int getDefaultDrawableResId() {
        return R.drawable.pull_to_refresh;
    }

    @Override
    protected void onLoadingDrawableSet(Drawable imageDrawable) {
        animationDrawable = (AnimationDrawable) imageDrawable;
    }

    @Override
    protected void onPullImpl(float scaleOfLayout) {
    }

    @Override
    protected void pullToRefreshImpl() {
        Log.e("=====11111=====", "执行了");
        mHeaderImage.clearAnimation();
        mHeaderImage.setVisibility(View.VISIBLE);
        mHeaderProgress.setVisibility(View.GONE);
        if (animationDrawable == mHeaderImage.getDrawable()) {
            animationDrawable.start();
        }
    }

    @Override
    protected void refreshingImpl() {
        mHeaderImage.clearAnimation();
        mHeaderImage.setVisibility(View.INVISIBLE);
        mHeaderProgress.setVisibility(View.VISIBLE);
    }

    @Override
    protected void releaseToRefreshImpl() {
        Log.e("=====33333=====", "执行了");
        animationDrawable.start();
    }

    @Override
    protected void resetImpl() {
        mHeaderImage.clearAnimation();
        mHeaderImage.setVisibility(View.GONE);
        mHeaderProgress.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onRefreshing() {
        mHeaderImage.clearAnimation();
        mHeaderImage.setVisibility(View.GONE);
        mHeaderProgress.setVisibility(View.VISIBLE);
    }
}
